<?php

namespace App\Http\Controllers\Company;
use Illuminate\Http\Request;
use App\Models\Personal\Resume;
use App\Models\Personal\ResumeComplain;
use App\Models\Common\CollOption;

class ResumeComplainController extends CommonController
{
    /**
     * 简历投诉
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function resumeComplain(Request $request){
        $user = auth()->guard('company')->user();
        if(!auth()->guard('company')->check()){ //非企业会员登录
            return 1;
        }
        
        $collOption     = CollOption::getOption('resume_complain');//分类表对应的记录
        $resumeComplain = ResumeComplain::where('company_uid', $user->uid)->where('resume_id', $request->resume_id)->first();
       
        $ids = array();
        if(!empty($resumeComplain)){
            $ids = explode(",",$resumeComplain->type);
        }
        return response()->json(['collOption'=>$collOption, 'ids'=>$ids]);
    }

    /**
     *  简历投诉提交异步
     * @param Request $request
     */
    public function resumeComplainSend(Request $request){
        $user = auth()->guard('company')->user(); 
        if(!auth()->guard('company')->check()){
            return 1;
        }
        $resumeComplain = ResumeComplain::where('company_uid', $user->uid)->where('resume_id', $request->resume_id)->first();

        if(empty($resumeComplain)){ //新增记录
            $input = [
            'type'=>$request->ids, 'company_uid'=>$user->uid, 'resume_id'=>$request->resume_id, 'created_at'=>date('Y-m-d H:i:s'),
                'updated_at'=>date('Y-m-d H:i:s')
            ];
            ResumeComplain::create($input);
        }else{ //修改记录
            ResumeComplain::where('id',$resumeComplain->id)->update(['type'=>$request->ids, 'updated_at'=>date('Y-m-d H:i:s')]);
        }  
    } 

}
